package com.yimi.yinhepda.entity.response;

import com.j256.ormlite.field.DatabaseField;
import com.yimi.yinhepda.utils.Common;
import com.yimi.yinhepda.utils.UcWaybillValidate;

import java.io.Serializable;
import java.math.BigDecimal;
import java.util.List;

/**
 * @author 000432
 */
public class LoadInfo implements Serializable {
    /**
     * 任务号
     */
    private String task;
    /**
     * 运单号/包号
     */
    private String waybillNo;
    /**
     * 开单件数
     */
    private Integer srcPiecesNum;
    /**
     * 库存件数
     */
    private Integer piecesNum;
    /**
     * 重量  ??
     */
    private BigDecimal weight;
    /**
     * 体积
     */
    private BigDecimal volume;
    /**
     * 计费重量
     */
    private BigDecimal chargedWeight;
    /**
     * 运单路由
     */
    private String waybillRoute;
    /**
     * 包号
     */
    private String packageNo;
    /**
     * 到达库区
     */
    private String areaCode;
    /**
     * 单据类型：1 运单，2 包
     */
    private Integer billType;
    /**
     * 配载单号
     */
    private String stowageNo;
    /**
     * 车牌号
     */
    private String carNo;
    /**
     * 强扫标记   空不是强扫   2是强扫
     */
    private transient String remark = "";
    private boolean isBigTicket = false;
    /**
     * 必走货字段 1-必走货，2-串货，3-标准,4-跨越
     */
    private String goodsPriority;
    /**
     * 产品类型：CP24-卡航 ,CP13-优
     */
    private String productType;
    /**
     * 下一站
     */
    private String nextDeptCode;
    private String nextDeptName;
    /**
     * 动态路由
     */
    private String dynamicRoute;
    /**
     * 运单子单集合
     */
    private List<QueryLoadDetailChildBillcode> childList;

    private int getScanCount = getScanCount();
    /**
     * 一级排序：红>黄>白>绿,getType
     */
    private int firstSort;
    /**
     * 二级排序： 时>比>优>串>标
     */
    private int secondSort = Common.GOODSP_RIORITY_DEFAULT;
    /**
     * 运单类型 1-快运 ，2-快递
     */
    private Integer waybillType;
    /**
     * 车标号
     */
    private String carMark;

    /**
     * 新旧重量比值
     */
    private BigDecimal weightRate;
    /**
     * 新旧体积比值
     */
    private BigDecimal volumeRate;
    /**
     * 装卸车运单类型:1-正常单  2-整车单,3-外传单 4-内转单 5-退货单,  6-签回单
     * 运单详情类型:1-正常单,2-中止单,3-作废单,4-退货单,5-签回单,6-整车单,7-外转单,8-内转单
     */
    private String kyWaybillType;
    /**
     * 是否有签回单业务
     */
    private Boolean isSingBack;
    /**
     * 签回单签收类型：1-原件返回，2-传真返回，3-照片返回，4-无返回
     */
    private String singBackType;
    /**
     * 到付付款金额(到付合计)
     */
    private BigDecimal paidPaymentAmount;
    /**
     * 代收款
     */
    private BigDecimal goodsChargeFee;
    /**
     * 是否自提 0-未自提，1-已自提,2-无需改单
     */
    private Integer isZiTi = 0;
    /**
     * 上下一站
     */
    private String relationDeptCode;
    /**
     * 上下一站名称
     */
    private String relationDeptName;
    /**
     * 上下一站部门类型
     */
    private Integer relationDeptType;

    private Integer isChangeDest; // //0未合并（默认），1合并  快递装车路由是否匹配


    public LoadInfo(String stowageNo, String remark, String carNo, Integer billType, String areaCode, String packageNo, String waybillRoute,
                    BigDecimal volume, BigDecimal chargedWeight, BigDecimal weight, Integer piecesNum, Integer srcPiecesNum, String waybillNo) {
        this.stowageNo = stowageNo;
        this.remark = remark;
        this.carNo = carNo;
        this.billType = billType;
        this.areaCode = areaCode;
        this.packageNo = packageNo;
        this.waybillRoute = waybillRoute;
        this.volume = volume;
        this.chargedWeight = chargedWeight;
        this.weight = weight;
        this.piecesNum = piecesNum;
        this.srcPiecesNum = srcPiecesNum;
        this.waybillNo = waybillNo;
    }

    public LoadInfo() {
    }

    public String getRelationDeptCode() {
        return relationDeptCode;
    }

    public void setRelationDeptCode(String relationDeptCode) {
        this.relationDeptCode = relationDeptCode;
    }

    public String getRelationDeptName() {
        return relationDeptName;
    }

    public void setRelationDeptName(String relationDeptName) {
        this.relationDeptName = relationDeptName;
    }

    public Integer getRelationDeptType() {
        return relationDeptType;
    }

    public void setRelationDeptType(Integer relationDeptType) {
        this.relationDeptType = relationDeptType;
    }

    public Integer getIsZiTi() {
        return isZiTi;
    }

    public void setIsZiTi(Integer isZiTi) {
        this.isZiTi = isZiTi;
    }

    public Boolean getSingBack() {
        return isSingBack;
    }

    public void setSingBack(Boolean singBack) {
        isSingBack = singBack;
    }

    public String getSingBackType() {
        return singBackType;
    }

    public void setSingBackType(String singBackType) {
        this.singBackType = singBackType;
    }

    public BigDecimal getPaidPaymentAmount() {
        return paidPaymentAmount;
    }

    public void setPaidPaymentAmount(BigDecimal paidPaymentAmount) {
        this.paidPaymentAmount = paidPaymentAmount;
    }

    public BigDecimal getGoodsChargeFee() {
        return goodsChargeFee;
    }

    public void setGoodsChargeFee(BigDecimal goodsChargeFee) {
        this.goodsChargeFee = goodsChargeFee;
    }

    public String getKyWaybillType() {
        return kyWaybillType;
    }

    public void setKyWaybillType(String kyWaybillType) {
        this.kyWaybillType = kyWaybillType;
    }

    public BigDecimal getWeightRate() {
        return weightRate;
    }

    public void setWeightRate(BigDecimal weightRate) {
        this.weightRate = weightRate;
    }

    public BigDecimal getVolumeRate() {
        return volumeRate;
    }

    public void setVolumeRate(BigDecimal volumeRate) {
        this.volumeRate = volumeRate;
    }

    public String getCarMark() {
        return carMark;
    }

    public void setCarMark(String carMark) {
        this.carMark = carMark;
    }

    public Integer getWaybillType() {
        return waybillType;
    }

    public void setWaybillType(Integer waybillType) {
        this.waybillType = waybillType;
    }

    public String getDynamicRoute() {
        return dynamicRoute;
    }

    public void setDynamicRoute(String dynamicRoute) {
        this.dynamicRoute = dynamicRoute;
    }

    public int getFirstSort() {
        return firstSort;
    }

    public void setFirstSort(int firstSort) {
        this.firstSort = firstSort;
    }

    public int getSecondSort() {
        return secondSort;
    }

    public void setSecondSort(int secondSort) {
        this.secondSort = secondSort;
    }

    public String getProductType() {
        return productType;
    }

    public void setProductType(String productType) {
        this.productType = productType;
    }

    public String getNextDeptCode() {
        return nextDeptCode;
    }

    public void setNextDeptCode(String nextDeptCode) {
        this.nextDeptCode = nextDeptCode;
    }

    public String getNextDeptName() {
        return nextDeptName;
    }

    public void setNextDeptName(String nextDeptName) {
        this.nextDeptName = nextDeptName;
    }

    public String getTask() {
        return task;
    }

    public void setTask(String task) {
        this.task = task;
    }

    public String getGoodsPriority() {
        return goodsPriority;
    }

    public void setGoodsPriority(String goodsPriority) {
        this.goodsPriority = goodsPriority;
    }

    public int getGetScanCount() {
        return getScanCount;
    }

    public void setGetScanCount(int getScanCount) {
        this.getScanCount = getScanCount;
    }

    public String getRemark() {
        return remark;
    }

    public void setRemark(String remark) {
        this.remark = remark;
    }

    public String getStowageNo() {
        return stowageNo;
    }

    public void setStowageNo(String stowageNo) {
        this.stowageNo = stowageNo;
    }

    public String getCarNo() {
        return carNo;
    }

    public void setCarNo(String carNo) {
        this.carNo = carNo;
    }

    public String getWaybillNo() {
        return waybillNo;
    }

    public void setWaybillNo(String waybillNo) {
        this.waybillNo = waybillNo;
    }

    public Integer getSrcPiecesNum() {
        if (srcPiecesNum == null) {
            srcPiecesNum = 0;
        }
        return srcPiecesNum;
    }

    public void setSrcPiecesNum(Integer srcPiecesNum) {
        this.srcPiecesNum = srcPiecesNum;
    }

    public Integer getPiecesNum() {
        if (piecesNum == null) {
            piecesNum = 0;
        }
        return piecesNum;
    }

    public Integer getIsChangeDest() {
        return isChangeDest;
    }

    public void setIsChangeDest(Integer isChangeDest) {
        this.isChangeDest = isChangeDest;
    }

    public void setPiecesNum(Integer piecesNum) {
        this.piecesNum = piecesNum;
    }

    public BigDecimal getWeight() {
        if (weight == null) {
            weight = BigDecimal.ZERO;
        }
        return weight;
    }

    public void setWeight(BigDecimal weight) {
        this.weight = weight;
    }

    public BigDecimal getVolume() {
        if (volume == null) {
            volume = BigDecimal.ZERO;
        }
        return volume;
    }

    public void setVolume(BigDecimal volume) {
        this.volume = volume;
    }

    public BigDecimal getChargedWeight() {
        if (chargedWeight == null) {
            chargedWeight = BigDecimal.ZERO;
        }
        return chargedWeight;
    }

    public void setChargedWeight(BigDecimal chargedWeight) {
        this.chargedWeight = chargedWeight;
    }

    public String getWaybillRoute() {
        return waybillRoute;
    }

    public void setWaybillRoute(String waybillRoute) {
        this.waybillRoute = waybillRoute;
    }

    public String getPackageNo() {
        return packageNo;
    }

    public void setPackageNo(String packageNo) {
        this.packageNo = packageNo;
    }

    public String getAreaCode() {
        return areaCode;
    }

    public void setAreaCode(String areaCode) {
        this.areaCode = areaCode;
    }

    public Integer getBillType() {
        if (billType == null) {
            billType = 0;
        }
        return billType;
    }

    public void setBillType(Integer billType) {
        this.billType = billType;
    }

    public List<QueryLoadDetailChildBillcode> getChildList() {
        return childList;
    }

    public void setChildList(List<QueryLoadDetailChildBillcode> childList) {
        this.childList = childList;
    }

    /**
     * 获得已扫数量
     */
    public int getScanCount() {
        if (childList == null || childList.size() == 0) {
            return 0;
        }
        int count = 0;
        for (QueryLoadDetailChildBillcode item : childList) {
            if (item.getFlag() == 1) {
                count++;
            }
        }
        return count;
    }

    /**
     * 获取已扫描的运单
     *
     * @return
     */
    public String getScanedWaybillNo() {
        if (childList != null && !childList.isEmpty()) {
            for (QueryLoadDetailChildBillcode item : childList) {
                if (item.getFlag() == 1) {
                    return item.getChildWaybillNo();
                }
            }
        }
        return null;
    }

    /**
     * 差异=扫描-开单   装车
     */
    public int getDifference() {
        if (srcPiecesNum == null) {
            srcPiecesNum = 0;
        }
        if ("2".equals(kyWaybillType) && getScanCount() > 0) {
            //整车单
            return 0;
        } else {
            return getScanCount() - (isBigTicket() ? 1 : srcPiecesNum);
        }
    }

    public int getType() {
        int dif = getDifference();
        if (getScanCount() == 0) {
            //白色
            return 1;
        } else if (dif < 0) {
            //红色
            return 0;
        } else if (dif > 0) {
            //黄色
            return 2;
        } else {
            //绿色
            return 3;
        }
    }

    public boolean isBigTicket() {
        return isBigTicket;
    }

    public void setBigTicket(boolean mBigTicket) {
        isBigTicket = mBigTicket;
    }

    public static LoadInfo parse(LoadInfo mQueryUnLoadDetailBillcode) {
        LoadInfo mQueryLoadDetailBillcode =
                new LoadInfo(mQueryUnLoadDetailBillcode.getStowageNo(), mQueryUnLoadDetailBillcode.getRemark(), mQueryUnLoadDetailBillcode.getCarNo(),
                        mQueryUnLoadDetailBillcode.getBillType(), mQueryUnLoadDetailBillcode.getAreaCode(), mQueryUnLoadDetailBillcode.getPackageNo(),
                        mQueryUnLoadDetailBillcode.getWaybillRoute(), mQueryUnLoadDetailBillcode.getVolume(), mQueryUnLoadDetailBillcode.getChargedWeight(),
                        mQueryUnLoadDetailBillcode.getWeight(), mQueryUnLoadDetailBillcode.getPiecesNum(), mQueryUnLoadDetailBillcode.getSrcPiecesNum(),
                        mQueryUnLoadDetailBillcode.getWaybillNo());
        mQueryLoadDetailBillcode.setChildList(mQueryUnLoadDetailBillcode.getChildList());
        return mQueryLoadDetailBillcode;
    }
}
